const path = require('path');
const VueLoaderPlugin = require('vue-loader/lib/plugin');
const HtmlWebpackPlugin = require('html-webpack-plugin');

const BASE_URL = '/';
module.exports = {
  entry: './src/main.js',
  output: {
    filename: 'bundle.js',
    path: path.resolve('./dist'),
  },
  module: {
    rules: [
      {
        // 处理vue单文件
        test: /.vue$/,
        use: 'vue-loader',
      },
      {
        test: /\.(js|vue)$/,
        loader: 'eslint-loader',
        enforce: 'pre',
        include: [path.resolve('src')],
        options: {
          // formatter: require('eslint-friendly-formatter'),
          emitWarning: false
        }
      },
      {
        // 它会应用到普通的 `.js` 文件
        // 以及 `.vue` 文件中的 `<script>` 块
        test: /\.js$/,
        loader: 'babel-loader',
        exclude: '/node_modules/',
      },
      {
        test: /.css$/,
        use: ['style-loader', 'css-loader'],
      },
      {
        // 用来处理less文件的第三方模块
        test: /\.less$/,
        use: ['style-loader', 'css-loader', 'less-loader'],
      },
      {
        test: /.(jpg|jpeg|png|gif|bmp)$/,
        use: {
          loader: 'url-loader',
          options: {
            esModule: false,
            limit: 10 * 1024, // 10KB
          },
        },

      },
    ],
  },
  plugins: [
    // 此插件由vue-loader提供，判断适应webpack版本
    new VueLoaderPlugin(),
    new HtmlWebpackPlugin({
      base_url: BASE_URL, // 需要这里传参
      template: './public/index.html',
    }),
  ],
};
